package com.chenziwen.scala.chapter08

object Scala11_ReduceFunction {
  def main(args: Array[String]): Unit = {
    // 化简
    val list = List(1, 2, 3, 4, 5)

    def minus(num1: Int, num2: Int): Int = {
      num1 - num2
    }

    // 效果：((((1 - 2) - 3) - 4) - 5) = -13
    println(list.reduceLeft(minus))
    // 效果：(1- (2- (3- (4-5)))) = 3
    println(list.reduceRight(minus))
  }
}
